

*****************************************************
*Summary stats of the regression sample (Table 1)*
*****************************************************

use "$data/regression_sample", clear
merge m:1 iris using "$data/matching/employee_shocks", keep(3) nogen

gen npatent_highcitation=npatent_quartile3+npatent_quartile4
gen npatent_lowcitation=npatent-npatent_highcitation
gen npatent_loworiginality=npatent-npatent_highoriginality
gen npatent_lowgenerality=npatent-npatent_highgenerality
gen npub_lowjif=npub-npub_highjif
gen npub_lowcite1=npub-npub_highcite1
gen npub_lowcite2=npub-npub_highcite2

tab umetrics_occ
sum total_direct_expenditure overhead_charged share_federal share_private share_other ncfda d_amountrd 
sum patent npatent npatent_lowcitation npatent_highcitation npatent_lowgenerality npatent_highgenerality npatent_privassignee 
sum pub npub npub_highcite2 npub_lowcite2 npub_highjif npub_lowjif npub_basic npub_applied npub_patent
sum npatent npub if umetrics_occ=="Faculty"
sum npatent npub if umetrics_occ=="Graduate Student"
sum npatent npub if umetrics_occ=="Staff"
sum npatent npub if umetrics_occ=="Undergraduate"

*****************************************************
*Summary stats by funding sources (Table 8) *
*****************************************************


use "$data/employee_cleaned.dta", clear

gen federal=(funding_type=="FEDERAL")
gen private= (strpos(funding_type,"PRIVATE")>0)
gen private_forprofit=(funding_type=="PRIVATE-FORPROFIT")
gen private_nonprofit=(funding_type=="PRIVATE-NONPROFIT")
gen other=1-federal-private

unique submit_u if federal==1
unique submit_u if private==1
unique submit_u if private_f==1
unique submit_u if private_n==1
unique submit_u if other==1

unique new_emp if federal==1
unique new_emp if private==1
unique new_emp if private_f==1
unique new_emp if private_n==1
unique new_emp if other==1

unique new_emp year_end if federal==1
unique new_emp year_end if private==1
unique new_emp year_end if private_f==1
unique new_emp year_end if private_n==1
unique new_emp year_end if other==1

unique submit_u unique_award if federal==1
unique submit_u unique_award if private==1
unique submit_u unique_award if private_f==1
unique submit_u unique_award if private_n==1
unique submit_u unique_award if other==1

merge m:1 unique using "$temp\award_amount", keep(1 3) nogen
bysort unique_award: gen temp=_n
bysort unique_award: egen teamsize=nvals(new_emp)
sum total_expenditure_award duration_award teamsize if federal==1&temp==1,d
sum total_expenditure_award duration_award teamsize if private==1&temp==1,d
sum total_expenditure_award duration_award teamsize if private_f==1&temp==1,d
sum total_expenditure_award duration_award teamsize if private_n==1&temp==1,d
sum total_expenditure_award duration_award teamsize if other==1&temp==1,d

unique new_emp if federal==1&umetrics_occ=="Faculty"
unique new_emp if private==1&umetrics_occ=="Faculty"
unique new_emp if private_f==1&umetrics_occ=="Faculty"
unique new_emp if private_n==1&umetrics_occ=="Faculty"
unique new_emp if other==1&umetrics_occ=="Faculty"

unique new_emp if federal==1&umetrics_occ=="Graduate Student"
unique new_emp if private==1&umetrics_occ=="Graduate Student"
unique new_emp if private_f==1&umetrics_occ=="Graduate Student"
unique new_emp if private_n==1&umetrics_occ=="Graduate Student"
unique new_emp if other==1&umetrics_occ=="Graduate Student"


unique new_emp if federal==1&umetrics_occ=="Post Graduate Research"
unique new_emp if private==1&umetrics_occ=="Post Graduate Research"
unique new_emp if private_f==1&umetrics_occ=="Post Graduate Research"
unique new_emp if private_n==1&umetrics_occ=="Post Graduate Research"
unique new_emp if other==1&umetrics_occ=="Post Graduate Research"

unique new_emp if federal==1&umetrics_occ=="Undergraduate"
unique new_emp if private==1&umetrics_occ=="Undergraduate"
unique new_emp if private_f==1&umetrics_occ=="Undergraduate"
unique new_emp if private_n==1&umetrics_occ=="Undergraduate"
unique new_emp if other==1&umetrics_occ=="Undergraduate"


*****************************************************
*Compare privately funded and publicly funded patents*
*****************************************************

use "$data\patent_umetrics", clear

ren app_year year
ren iris emp_num_2018
merge m:1 emp_num_2018 using "$rawdata\emp_num_xwalk_reverse", keep(1 3) nogen
ren emp_num_2019 iris_employee_number

merge m:1 iris year using "$data\final_multicfda", keepus(faculty total_direct* amount*) keep(1 3) nogen

gen share_federal_expenditure=total_direct_federal/total_direct_expenditure
gen share_private_expenditure=total_direct_private/total_direct_expenditure
gen share_forprofit_expenditure=total_direct_forprofit/total_direct_expenditure
gen share_nonprofit_expenditure=total_direct_nonprofit/total_direct_expenditure

gen federal=(share_federal_expenditure>0.5&share_federal_expenditure<.)
gen private=(share_private_expenditure>=0.5&share_private_expenditure<.)
gen forprofit=(share_forprofit_expenditure>=0.5&share_forprofit_expenditure<.)
gen nonprofit=(share_nonprofit_expenditure>=0.5&share_nonprofit_expenditure<.)
gen other=(share_federal_expenditure!=.&federal==0&private==0)

gen assigneetype="University" if strpos(org,"University")>0
replace assigneetype="University" if strpos(org,"Alumni")>0
replace assigneetype="University" if strpos(org,"Penn State")>0
replace assigneetype="University" if strpos(org,"Purdue")>0
replace assigneetype="University" if strpos(org,"UNIVERSITY")>0
replace assigneetype="University" if strpos(org,"College")>0
replace assigneetype="University" if strpos(org,"Institute of Technology")>0
replace assigneetype="University" if strpos(org,"Unversity")>0
replace assigneetype="University" if strpos(org,"STC.UNM")>0

replace assigneetype="Government" if strpos(org,"United States")>0
replace assigneetype="Government" if strpos(org,"National")>0
replace assigneetype="Government" if strpos(org,"U.S. ")>0

replace assigneetype="Nonprofit" if strpos(org,"Foundation")>0&assigneetype==""
replace assigneetype="Nonprofit" if strpos(org,"Research Institute")>0&assigneetype==""

replace assigneetype="Forprofit" if strpos(org,"Company")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"COMPANY")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"Corporation")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"CORPORATION")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"Inc")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"Limited")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"Corp")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"Ltd")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"INC")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"LLC")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"GmbH")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"BASF")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"L.P.")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org," AG")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"Hospital")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"Canon ")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"Siemens")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"Toyota")>0&assigneetype==""
replace assigneetype="Forprofit" if strpos(org,"Sanofi")>0&assigneetype==""


sum originality generality scaled*  if federal==1
sum originality generality scaled* if private==1
sum originality generality scaled* if forprofit==1
sum originality generality scaled* if nonprofit==1
sum originality generality scaled* if other==1

tab assigneetype if federal==1
tab assigneetype if private==1
tab assigneetype if forprofit==1
tab assigneetype if nonprofit==1
tab assigneetype if other==1


*****************************************************
*Compare privately funded and publicly funded publications*
*****************************************************


use "$pub\medline_umetrics_xwalk", clear

merge m:1 pmid using "$pubmed\pmid_citations", keep(1 3) nogen

merge m:1 pmid using "$pubmed\pmid_journalid", keep(1 3) nogen

merge m:1 pmid using "$pubmed\basicness", keep(1 3) nogen

ren pub_year year
ren emp_number emp_num_2020
merge m:1 emp_num_2020 using "$rawdata\emp_num_xwalk_2020", keep(1 3) nogen
ren emp_num_2019 iris_employee_number

merge m:1 iris year using "$data\final_multicfda", keepus(faculty total_direct* amount*) keep(1 3) nogen

gen share_federal_expenditure=total_direct_federal/total_direct_expenditure
gen share_private_expenditure=total_direct_private/total_direct_expenditure
gen share_forprofit_expenditure=total_direct_forprofit/total_direct_expenditure
gen share_nonprofit_expenditure=total_direct_nonprofit/total_direct_expenditure

gen federal=(share_federal_expenditure>0.5&share_federal_expenditure<.)
gen private=(share_private_expenditure>=0.5&share_private_expenditure<.)
gen forprofit=(share_forprofit_expenditure>=0.5&share_forprofit_expenditure<.)
gen nonprofit=(share_nonprofit_expenditure>=0.5&share_nonprofit_expenditure<.)
gen other=(share_federal_expenditure!=.&federal==0&private==0)

sum jif fcites_3yr fcites_lifetime level_score cited_patent if federal==1



